﻿using UnityEngine;

namespace BlockOS.Client.Res
{
    public class TextureBindPoint
    {
        public string name;
        private TextureBindPoint from = null;
        private TextureTarget target = null;

        public class TextureTarget
        {
            public string textureName;
            public Vector4 uv;
        }

        public TextureTarget Target
        {
            get
            {
                if (target != null)
                {
                    return target;
                }
                else if (from != null)
                {
                    return from.Target;
                }
                return null;
            }
        }

        public bool IsBound => Target != null;

        public TextureBindPoint(string name)
        {
            this.name = name;
        }

        public void SetAlias(TextureBindPoint point)
        {
            from = point;
        }

        public void Bind(string textureName)
        {
            Bind(textureName, new Vector4(0, 0, 1, 1));
        }

        public void Bind(string textureName, Vector4 uv)
        {
            target = new TextureTarget
            {
                textureName = textureName,
                uv = uv,
            };
        }
    }
}
